package com.rp.infopub.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rp.infopub.dao.ArticleDao;
import com.rp.infopub.dao.ChannelDao;
import com.rp.infopub.po.Article;
import com.rp.infopub.po.Channel;

@Service
@Transactional
public class ChannelService {
	
	@Autowired
	private ChannelDao channelDao;
	@Autowired
	private ArticleDao articleDao;
	
	public String saveChannel(Channel channel){
		return (String) channelDao.save(channel);
	}
	
	public void updateChannel(Channel channel){
		List<Article> arts = articleDao.find(ArticleDao.GET_ARTICLES_BY_CHANNELID, channel.getId());
		for (Article art : arts) {
			art.setChannelName(channel.getName());
			articleDao.update(art);
		}
		channelDao.update(channel);
	}
	
	public void deleteChannel(String channelId){
		channelDao.delete(channelId);
	}
	
	
	
	public ChannelDao getChannelDao() {
		return channelDao;
	}
	
}
